package com.mtung.concurrent.thread;

/**
 * @author zhenguo.yao
 * @date 2020/12/25
 */
public class Thread06 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+","+i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        test1();
        test2();
    }

    /**
     * 打印结果每次都不同,无序
     */
    public static void test1(){
        Thread t1 = new Thread(new Thread06(), "t1");
        Thread t2 = new Thread(new Thread06(), "t2");
        Thread t3 = new Thread(new Thread06(), "t3");
        t1.start();
        t2.start();
        t3.start();
        System.out.println(Thread.currentThread().getName()+"执行结束...");
    }

    /**
     * 先执行
     */
    public static void test2() throws InterruptedException {
        Thread t1 = new Thread(new Thread06(), "t1");
        Thread t2 = new Thread(new Thread06(), "t2");
        Thread t3 = new Thread(new Thread06(), "t3");
        t1.start();
        t1.join();
        t2.start();
        t2.join();
        t3.start();
        t3.join();
        System.out.println(Thread.currentThread().getName()+"执行结束...");
    }
}
